#include "CQBase.h"

namespace CQLIB
{
	LIBZCQ_API hash_table_t* CQHT_CreateCQHash(table_mode_t mode)
	{
		return htnew(mode);
	}

	LIBZCQ_API int CQHT_SetData(hash_table_t* table, const void* k, size_t key_len, void* v, size_t value_len)
	{
		return htset(table, k, key_len, v, value_len);
	}

	LIBZCQ_API int CQHT_SetDataNx(hash_table_t* table, const void* k, size_t key_len, void* v, size_t value_len)
	{
		return htsetnx(table, k, key_len, v, value_len);
	}

	LIBZCQ_API void* CQHT_GetValue(hash_table_t* table, const void* k, size_t key_len)
	{
		return htget(table, k, key_len);
	}

	LIBZCQ_API hash_table_element_t* CQHT_GetAll(hash_table_t* table, table_mode_t mode)
	{
		return htgetall(table, mode);
	}

	LIBZCQ_API void CQHT_ReHash(hash_table_t* table, hash_size_t seed)
	{
		htrh(table, seed);
	}

	LIBZCQ_API int CQHT_RemoveData(hash_table_t* table, const void* key, size_t key_len)
	{
		return htrm(table, key, key_len);
	}

	LIBZCQ_API void CQHT_DestoryHash(hash_table_t* table)
	{
		htdel(table);
	}
#if defined(__x86_64__) || defined(_WIN64)
	LIBZCQ_API CQH64_hash_t CQHT_CQHash(const void* input, size_t len, hash_size_t seed)
#else
	LIBZCQ_API CQH32_hash_t CQHT_CQHash(const void* input, size_t len, hash_size_t seed)
#endif
	{
		return CQHASH(input, len, seed);
	}

	LIBZCQ_API void CQAES_encData(const uint8_t* in, size_t in_len, uint8_t* out, const uint8_t* key, size_t key_len)
	{
		aes_cipher_data(in, in_len, out, key, key_len);
	}

	LIBZCQ_API void CQAES_decData(const uint8_t* in, size_t in_len, uint8_t* out, size_t* out_len, const uint8_t* key, size_t key_len)
	{
		aes_decipher_data(in, in_len, out, out_len, key, key_len);
	}

	LIBZCQ_API int CQAES_encFile(const char* in_filename, const char* out_filename, const uint8_t* key, size_t key_len)
	{
		return aes_cipher_file(in_filename, out_filename, key, key_len);
	}

	LIBZCQ_API int CQAES_decFile(const char* in_filename, const char* out_filename, const uint8_t* key, size_t key_len)
	{
		return aes_decipher_file(in_filename, out_filename, key, key_len);
	}

	LIBZCQ_API void CQSHA2_sha224(const unsigned char* message, unsigned int len, unsigned char* digest)
	{
		sha224(message, len, digest);
	}

	LIBZCQ_API void CQSHA2_sha256(const unsigned char* message, unsigned int len, unsigned char* digest)
	{
		sha256(message, len, digest);
	}

	LIBZCQ_API void CQSHA2_sha384(const unsigned char* message, unsigned int len, unsigned char* digest)
	{
		sha384(message, len, digest);
	}

	LIBZCQ_API void CQSHA2_sha512(const unsigned char* message, unsigned int len, unsigned char* digest)
	{
		sha512(message, len, digest);
	}

	LIBZCQ_API void CQSHA2_Data(const unsigned char* message, unsigned int len, unsigned char* digest, sha_mode mode)
	{
		SHA2_Data(message, len, digest, mode);
	}

	LIBZCQ_API void CQSHA2_File(const char* filename, unsigned char* digest, sha_mode mode)
	{
		SHA2_File(filename, digest, mode);
	}

	LIBZCQ_API void CQMD5_md5File(const char* filename, unsigned char* digest)
	{
		MD5File(filename, digest);
	}

	LIBZCQ_API void CQMD5_md5Data(const unsigned char* data, unsigned int len, unsigned char* digest)
	{
		MD5Data(data, len, digest);
	}
}